﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace ABC.Billing
{
    public class Billing : IBilling
    {
        public static OleDbDataReader getBillingInfo(long invoice)
        {
            string sqlString = "select * from tabBilling where invoice = " + invoice;

            OleDbCommand command = new OleDbCommand(sqlString, ABC.Database.DataBaseConnection.MyConn);
            OleDbDataReader dtrCat = command.ExecuteReader();

            return dtrCat;
        }
    }

    public class BillingHelper
    {
        /// <summary>
        /// returns a Bill code if there exists one for the particular invoice. 
        /// </summary>
        /// <param name="invoice"></param>
        /// <returns></returns>
        public static string getBillCode(long invoice)
        {
            StringBuilder billCode = new StringBuilder();

            string sqlString = "select CODE from tabBilling where CODE is not null and invoice = " + invoice;
            OleDbCommand command = new OleDbCommand(sqlString, ABC.Database.DataBaseConnection.MyConn);
            OleDbDataReader areader = command.ExecuteReader();

            while (areader.Read())
            {
                billCode.Append(areader["CODE"].ToString());
            }
            
            return billCode.ToString();
        }
    }
}
